﻿using System;
using System.Collections.Generic;
using System.Xml;
using umbraco.MacroEngines;

namespace Lu.Blog.Domain.Utils
{
    public static class XmlNodePickerHelper
    {
        public static IEnumerable<DynamicMedia> GetImagesFromPicker(string xmlString)
        {
            if (!string.IsNullOrEmpty(xmlString))
            {
                var xml = new XmlDocument();
                xml.LoadXml(xmlString);
                foreach (dynamic idStr in xml.FirstChild.ChildNodes)
                {
                    var id = Convert.ToInt32(idStr.InnerText);
                    yield return new DynamicMedia(id);
                }
            }
        }

        public static IEnumerable<DynamicNode> GetContentNodesFromPicker(string xmlString)
        {
            if (!string.IsNullOrEmpty(xmlString))
            {
                var xml = new XmlDocument();
                xml.LoadXml(xmlString);
                foreach (dynamic idStr in xml.FirstChild.ChildNodes)
                {
                    var id = Convert.ToInt32(idStr.InnerText);
                    yield return new DynamicNode(id);
                }
            }
        }
    }
}